import {
	$get,
	$post
} from '@/puigins/request.js';

export function search(search, engine) {
	return new Promise((resolve, reject) => {
		$get('/nav/search', {
			search,
			engine
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getBg() {
	return new Promise((resolve, reject) => {
		$get('/nav/getBg').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getWeather() {
	return new Promise((resolve, reject) => {
		$get('/nav/getWeather').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getHistory() {
	return new Promise((resolve, reject) => {
		$get('/nav/getHistory').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getNavSite() {
	return new Promise((resolve, reject) => {
		$get('/nav/getNavSite').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getRecommend() {
	return new Promise((resolve, reject) => {
		$get('/nav/getRecommend').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function delNav(id) {
	return new Promise((resolve, reject) => {
		$post('/nav/delNav', {
			id
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}

export function delNavHistory(id) {
	return new Promise((resolve, reject) => {
		$post('/nav/delNavHistory', {
			id
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function proxy(url) {
	return new Promise((resolve, reject) => {
		$post('/nav/proxy', {
			url
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function addNavSite(form) {
	return new Promise((resolve, reject) => {
		$post('/nav/addNavSite', form).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function addHistory(id) {
	return new Promise((resolve, reject) => {
		$post('/nav/addHistory', {
			id
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}

export function getHotSearch() {
	return new Promise((resolve, reject) => {
		$get('/nav/getHotSearch').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function getSiteLogoAndTitle(url) {
	return new Promise((resolve, reject) => {
		$post('/nav/getSiteLogoAndTitle', { url }, { timeout: 10000 }).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}